<extend name="Base/common"/>
<block name="header">
    <include file="Public/nav"/>
</block>
<block name="body">
    <link type="text/css" rel="stylesheet" href="__PUBLIC__/js/ext/zf/css/zebra_form.css"/>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/js/ext/webuploader/js/webuploader.js"></script>
    <link href="__PUBLIC__/js/ext//webuploader/css/webuploader.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/js/ext/webuploader/js/webuploader.js"></script>
    <link href="__PUBLIC__/js/ext/webuploader/css/webuploader.css" type="text/css" rel="stylesheet">

    <style>
        .web_uploader_picture_list {
            margin-top: 10px;
        }

        .web_uploader_picture_list img {
            width: 80px;
            height: 80px;
        }
    </style>

    <div class="container common-block-lg templet" style="width: 700px">

        <div class="row">

            <div class="">
                <div class="with-padding">
                    <form class="form-horizontal ajax-form" role="form" method="post" action="__SELF__">
                        <legend>绑定网站</legend>
                        <div class="alert alert-success">
                            > 绑定网站之后，您可以在线安装扩展。<br/><span class="text-danger">> 网站一经绑定无法随意更改，请谨慎绑定，您在{$MODULE_ALIAS}所购买的商品都将和您的域名绑定。</span>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">域名</label>
                            <div class="col-md-6">
                                <input type="text" name="domain" id="domain" placeholder="无法获取，请手动填写，不要http://" value="{$website.domain}"
                                       class="form-control">
                            </div>
                            <a href="javascript:" class="btn btn-success btn-xs" data-role="show_check_btn" style="line-height: 26px;"  ><i class="icon-check"></i> 验证</a>

                            <input type="hidden" name="is_checked" value="0">

                        </div>

                        <div class="form-group">
                            <label class="col-md-2 control-label">网站名</label>
                            <div class="col-md-6">
                                <input type="text" name="title" placeholder="无法获取，请手动填写" id="title" value="{$website.title}"
                                       class="form-control">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-md-2 control-label">持有人</label>

                            <div class="col-md-6">
                                <input type="text" name="master" id="master" value="{$website.master}" class="form-control" >
                                <span class="text-muted"> Tip:</span> 公司写公司名，个人写姓名
                            </div>
                        </div>
                        <eq name="website.domain" value="">
                            <script>
                                window.addEventListener('message', function (event, domain) {
                                    if (event.data.type == 'returnWebSiteInfo') {
                                        $('#domain').val(event.data.domain);
                                        $('#title').val(event.data.title);
                                        $('#ip').val(event.data.ip);
                                    }
                                });
                                appstoreMessage.getWebsiteInfo();
                            </script>
                        </eq>


                        <div class="form-group">
                            <div class="col-md-offset-2 col-md-10">
                                <input type="submit" id="submit" class="btn btn-primary" value="绑定"
                                       data-loading="稍候...">
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>

    </div>

    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__STATIC__/ueditor/ueditor.all.min.js"></script>

    <script type="text/javascript" src="__PUBLIC__/js/ext/zf/js/zebra_form.js"></script>

    <script>
        $(function(){
            var html = ' <div class="show_check_div"><div>请在网站根目录下创建一个任意内容的 appstore.txt 文件。<br>域名请不要加http://，直接填域名部分，如v2.opensns.cn；<br><span style="font-weight: bolder">如协议为https://则请在域名前加上协议</span><br/><a class="btn btn-primary" style="font-weight:bold" data-role="check_website">点击验证</a>' +
                    '<div id="show_info"></div></div></div>';
            $('[data-role="show_check_btn"]').popover({content:html, trigger: 'click', placement: 'right', html: true,title:'网址验证'})
            $('[data-role="show_check_btn"]').on('shown.bs.popover', function () {
                bind_check_website();
            })
        })

        var bind_check_website = function(){
            $('[data-role="check_website"]').unbind('click');
            $('[data-role="check_website"]').click(function(){
                $.post(U('appstore/admin/checkWebsite'),{website:$('#domain').val()},function(res){
                    var $show = $('#show_info');
                    if(res.status){
                        toast.success(res.info);
                        $show.css('color','green')
                        $('[name="is_checked"]').val(1);
                    }else{
                        toast.error(res.info);
                        $show.css('color','red')
                    }
                    $show.html(res.info)
                })
            })
        }
    </script>

</block>